package com.truthbean.log.log4j;

import com.truthbean.log.Logger;
import com.truthbean.log.util.MsgHelper;
import org.apache.log4j.Level;

/**
 * @author TruthBean
 * @since 0.0.1
 */
public class Log4jImpl implements Logger {

    /**
     * this class name
     */
    private static final String FQCN = Log4jImpl.class.getName();

    /**
     * log4j logger
     */
    private org.apache.log4j.Logger log;

    public Log4jImpl() {
    }

    @Override
    public void error(String s, Throwable e) {
        log.log(FQCN, Level.ERROR, s, e);
    }

    @Override
    public void debug(String s) {
        log.log(FQCN, Level.DEBUG, s, null);
    }

    @Override
    public void info(String msg) {
        log.log(FQCN, Level.INFO, msg, null);
    }

    @Override
    public void info(String msg, Object... param) {
        log.log(FQCN, Level.INFO, MsgHelper.format(msg, param), null);
    }

    @Override
    public void debug(String msg, Object... param) {
        log.log(FQCN, Level.DEBUG, MsgHelper.format(msg, param), null);
    }

    @Override
    public void setClass(Class<?> clazz) {
        log = org.apache.log4j.Logger.getLogger(clazz);
    }

    @Override
    public void setClassName(String className) {
        log = org.apache.log4j.Logger.getLogger(className);
    }
}